{include file="public/header"}

<body>
    <div class="layui-fluid">
        <div class="layui-row">
            <form action="" method="post" class="layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                        <span class="x-red">*</span> 账号
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="username" name="username" value="{$admin.username}" required="" lay-verify="required" autocomplete="off"
                               class="layui-input" readonly>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                        <span class="x-red">*</span> 昵称
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="name" name="nickname" value="{$admin.nickname|default=''}" required="" lay-verify="required" autocomplete="off"
                            class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                        <span class="x-red">*</span> 密码
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="password" name="password" value="" autocomplete="off"
                            class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                        <span class="x-red">*</span> 确认密码
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="passworder" name="passworder" value="" autocomplete="off"
                            class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <button class="layui-btn" lay-submit="" lay-filter="add">提交</button>
                </div>
            </form>
        </div>
    </div>
    {include file="public/footer"}

    <script>
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
            var form = layui.form
                ,layer = layui.layer;

            //监听提交
            form.on('submit(add)', function(data){
                console.log(data);
                //发异步，把数据提交给php
                $.ajax({
                    'type': 'post',
                    data: data.field,
                    success: function (res) {
                        console.log(res);
                        if (res.status == 0) {
                            layer.msg(res.msg, {icon: 6, time: 1000},function () {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(res.msg, {icon: 2, time: 1000});
                        }
                    }
                });
                return false;
            });

        });
    </script>